const bcrypt = require('bcrypt')

const SALT = 10;

// bcrypt 加密
const hashPassword = (password) => {
  return new Promise((resolve, reject) => {
    bcrypt.hash(password,SALT,(err,encrypted)=>{
        if(err){
            reject(err)
        }
        resolve(encrypted)
    })
  });
};


// 密码验证
const matchPassword = (password, oldHashPwd) => {
  return new Promise(async (resolve, reject) => {
    const match = await bcrypt.compare(oldHashPwd,password)
  });
};

module.exports = {hashPassword,matchPassword}

// //测试
// async function test2() {
//     const pass = 'gt'
//     const  hashPWD = await  hashPassword(pass)
//     console.log("hashPWD:",hashPWD); 
//     const match = await matchPassword(hashPWD,'gt1')
//     console.log("Password matches:",match);
// }

// test2()